<?php
		 
					$loaihienthi=0;//0 là theo thời gian, 1 là theo giá,2 theo vùng, 3 theo tỉnh, 4 theo sp, 5 theo loại sp,6 tất cả				
					if(isset($_GET["idht"]))
						$loaihienthi = $_GET["idht"];
					$dstrvBUS = new TinRaoVatBUS;			
					$sanphamBUS= new SanPhamBUS();
					$tinhBUS =  new TinhBUS();
					
					$sodong = 20;//số sản phẩm trên 1 trang
					if(!isset($_GET["p"]))
								$p=1;//p là trang
					else
						$p = $_GET["p"];
						
					 
					switch($loaihienthi)
					{
						case 0: 
						{
							$soluongsp = $dstrvBUS->getSoLuongTRV();
							$sotrang = ceil($soluongsp/$sodong);							 
							$x = ($p-1)*$sodong;
							$dstrv = $dstrvBUS->getTinRaoVatSortByTime($x, $sodong);
							break;							
						}
						case 1:
						{
							$dstongtrv = $dstrvBUS->getTinRaoVatSortByGiaASC();
							break;
						}
						case 2:
						{
							$maVung = $_GET["idMaVung"]; 
							$soluongsp = $dstrvBUS->getSoLuongTRVByMaVung($maVung);
							$sotrang = ceil($soluongsp/$sodong);							
							$x = ($p-1)*$sodong;														
							$dstrv = $dstrvBUS->getTinRaoVatByMaVung($maVung, $x, $sodong);	
							break;
						}
						case 3:
						{
							$maTinh = $_GET["idMaTinh"];
							$soluongsp = $dstrvBUS->getSoLuongTRVByMaTinh($maTinh);
							$sotrang = ceil($soluongsp/$sodong);							
							$x = ($p-1)*$sodong;														
							$dstrv = $dstrvBUS->getTinRaoVatByMaTinh($maTinh, $x, $sodong);
							break;
						}
						case 4:
						{
							$maDMSP = $_GET["idMaDMSP"];
							$soluongsp = $dstrvBUS->getSoLuongTRVByMaDMSP($maDMSP);
							$sotrang = ceil($soluongsp/$sodong);							
							$x = ($p-1)*$sodong;
							$dstrv =  $dstrvBUS->getTinRaoVatByMaDMSP($maDMSP, $x, $sodong);
							break;	
						}
						case 5:
						{
							$maSP = $_GET["idMSP"];
							$soluongsp = $dstrvBUS->getSoLuongTRVByMaSP($maSP);
							$sotrang = ceil($soluongsp/$sodong);							
							$x = ($p-1)*$sodong;
							$dstrv = $dstrvBUS->getTinRaoVatByMaSP($maSP, $x, $sodong);
							break;
						}
						case 6:
						{
							$texttk =$_POST["texttk"];
							$vungtk = $_POST["vungtk"];
							$sptk = $_POST["sanphamtk"];
							$loai = $_POST["loai"];
							$giatu= $_POST["giatu"];
							$giden= $_POST["giaden"];
							$soluongsp = $dstrvBUS->getSoLuongTRVByTieuDe($texttk , 0, 10000000);
							$sotrang = ceil($soluongsp/$sodong);							
							$x = ($p-1)*$sodong;
							$dstrv=$dstrvBUS->getTRVByTieuDe($texttk, 0, 10000000, $x, $sodong);
							break;
						}
						 
						
					}				 
					 					
					
					 					
					
					//$dstrv=$dstongtrv;
					// = $dstrvBUS->getTinRaoVatPaging($x,$sodong);//phân trang tin rao vặt
					
					
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title><link rel="stylesheet" type="text/css" href="css/sanpham1.css"/>
 
</head>

<body>
<div class="list_container"> 
    <div class="listing_tabs">
         <div id="tabarea_left">
            <ul id="tabnav">
                <li class="tab_all tab_active">
                            <strong>Tất&nbsp;cả có</strong><strong> <?php echo " ".$soluongsp;?></strong> sản phẩm
                </li>
                <li class="tab_private tab_inactive">
                    <a  href="#" title="Chỉ hiển thị tin rao của cá nhân" onclick="#">Cá&nbsp;nhân<span class="tab_right_links">, 45987</span></a>
                </li>                
                <li class="tab_company tab_inactive">
                    <a  href="#" title="Chỉ hiển thị tin quảng cáo của công ty" onclick="#">Công&nbsp;ty<span class="tab_right_links">, 24307</span></a>
                </li>
            </ul>
            <div class="clear"></div>
         </div>
         <div id="tabarea_right">
              <ul class="lastnav" id="tabnav">
               <li class="tab_right">
                  <div class="btn_order_group"> <a onclick="xt_med('C',xtn2,'hide_thumbnail','A'); return common.set_md('th');" href="http://www.chotot.vn/hà_nội/" title="Xem hình thu nhỏ" class="sort_price sort_left sort_active" rel="nofollow">
                      <div class="thumbs_img">
                          <div class="ll_item">
                              <div class="thumbs_dot"></div>
                              <div class="thumbs_line"></div>
                          </div>
                          <div class="ll_item">
                              <div class="thumbs_dot"></div>
                              <div class="thumbs_line"></div>
                          </div>
                          <div class="ll_item">
                              <div class="thumbs_dot"></div>
                              <div class="thumbs_line"></div>
                          </div>
                       </div></a>  
                     <a onclick="xt_med('C',xtn2,'hide_thumbnail','A'); return common.set_md('li');" href="#" title="Ẩn hình thu nhỏ" class="sort_price sort_right sort_inactive" rel="nofollow">
                      <div class="thumbs_img">
                            <div class="ll_item"><div class="no_thumbs_line">&nbsp;</div>
                      </div>
                      <div class="ll_item">
                            <div class="no_thumbs_line">&nbsp;</div>
                       </div><div class="ll_item">
                            <div class="no_thumbs_line">&nbsp;</div>
                       </div>
                       <div class="ll_item">
                            <div class="no_thumbs_line">&nbsp;</div>
                       </div>
                   </div></a>
          </div> 
         <div id="price_container"> <a href="index.php" title="Tin&nbsp;mới&nbsp;trước" class="clock sort_left sort_active" >
              <div class="cl_image"><div>&nbsp;</div>
              </div></a> <a href="index.php?idht=<?php echo 1 ?>" title="Giá rẻ trước" class="clock sort_right sort_inactive"><span class="vnd">VND</span><span class="down_arrow">↓</span></a>
          </div>  </li></ul>
      </div>
    <div class="clear"></div> 
</div> <!-- List container -->  <!-- Box container -->
<div class="_container">	
	<div class="box_container ">
		<div>
			<div class="content global_sprite_x">
				 <div class="box"> 
                 	<div>  <!-- Tab -->  
                    	<div class="TabContainer"> 
                        	<div class="listing-rows"> <!-- Ads --> 
                            <?php  //danh sách tin rao vặt							
								if($dstrv!=NULL){
								foreach ($dstrv as $objtrv){
								?>
                            	<div id="hl" class="listing_thumbs">  
                                	<div class="chotot-list-row"> 
                                    	<div class="listing_thumbs_image">  
                                        	<div class="extra_img"> <a href="chitiettinraovat.php?idMatrv=<?php echo $objtrv->getMaTRV(); ?>"> <img width="70" height="70" border="0" title="<?php echo $objtrv->getNoiDung();?>" alt=""
                                             src="<?php $chuoi = explode(" ",$objtrv->getHinhAnh()); echo $chuoi[0];?> " class="thumbnail"> </a> </div>    
                                        </div>             
                                        <div class="thumbs_subject" nowrap="nowrap"> <a class="ad-subject" href="chitiettinraovat.php?idMatrv=<?php echo $objtrv->getMaTRV(); ?>" title="Laptop lenovo "> <?php echo $objtrv->getTieuDe(); ?>  </a><br>
                                         	  <div class="ad-price"> <?php echo $objtrv->getGiaCa(); ?> VNĐ  </div>   <a title=" " href="" class="ad-category-region" onclick="xt_click(this,'C',xtn2,'subcategory_in_region','N');">
											  <?php $sanpham = $sanphamBUS->getSanPhamByMaSP($objtrv->getMaSP());
											  echo $sanpham->getTenSP(); ?>  
                                               <span class="municipality">ở <?php
											   if($tinhBUS->getTinhByMaTRV($objtrv->getMaTRV())!=NULL){
											   $tinh = $tinhBUS->getTinhByMaTRV($objtrv->getMaTRV());			    
											  	foreach($tinh as $objtinhmrv) echo " ".$objtinhmrv->getTenTinh(); ?><!-- ở --></span><?php }?>    </a> <span class="subtext">  </span>
                                         </div>   
                                        <div class="listing_thumbs_date" nowrap="nowrap"><?php echo $objtrv->getNgayRao();?></div>
                                          <div class="clear_row">
                                          </div>
                                    </div>  
               <!-- Ads end --></div><?php  }?>				    
                 							
                   
                 			  <div class="clear"></div>
                              <div class="paging_container"> 
                                    	<div class="resultcontainer"> 
                                        	<div border="0" cellspacing="0" cellpadding="0" class="paging_table"> 
                                            	<div class="paging_first_page_link"> &nbsp; </div> 
                                                 <div class="paging_links"> 
                                                    <ul class="pagination_ul"> 
                                                    <?php for($i=1;$i<=$sotrang;$i++)
                                                    {	?>											 
                                                                                                         
                                                         <li class="pagination_li"><a href="index.php?p=<?php echo $i;?>&&idht=<?php echo $$loaihienthi;?>" class="pagination_link"><?php echo $i;?></a></li> 
                                                           <?php }?>
                                                           
                                                     </ul> 
                                                </div> 
                                                <div class="paging_last_page_link">  <a href="index.php?p=<?php echo $sotrang;?>&&idht=<?php echo $$loaihienthi;?>"   class="pagination_last_link left_border">Trang cuối</a>
                                                </div> 
                                                 <div class="clear">
                                                 </div> 
                                         	</div> 
                                     	</div>   
                              </div> 
                              <?php }else echo "không tìm thấy kết quả";?>
                          </div> 
                     	</div> <!-- Banner list --> 
                    </div> 
                   <div id="banner_list">  </div>  <!-- Banner list end --> 
                </div> 
             </div>
        </div>
    </div>
</div>
<!-- Box container end -->
</div>
</body>
	 
</html> 